#!/bin/bash

#Se chequea que todo este bien
if [ $# -ne "1" ]
then
	echo "USO: ${0} <SERVER_NAME>"
	exit 0
fi

SERVER_NAME=${1}

source config.sh  # incluyo las constantes

if [ "${SERVER_NAME}" == "WEBSERVER" ]
then
	TAP=${WEBSERVER[0]}

elif [ "${SERVER_NAME}" == "FTPSERVER" ]
then
	TAP=${FTPSERVER[0]}

elif [ "${SERVER_NAME}" == "TELSERVER1" ] || [ "${SERVER_NAME}" == "TELSERVER" ]
then
	TAP=${TELSERVER1[0]}

elif [ "${SERVER_NAME}" == "TELSERVER2" ]
then
	TAP=${TELSERVER2[0]}

elif [ "${SERVER_NAME}" == "HOSTA" ]
then
	TAP=${HOSTA[0]}

elif [ "${SERVER_NAME}" == "HOSTB" ]
then
	TAP=${HOSTB[0]}

elif [ "${SERVER_NAME}" == "HOSTC" ]
then
	TAP=${HOSTC[0]}

else
	echo "El TAP debe ser: 'WEBSERVER', 'FTPSERVER', 'TELSERVER', 'TELSERVER1', 'TELSERVER2', 'HOSTA', 'HOSTB' O 'HOSTC'"
	exit 1
fi


sudo openvpn --rmtun --dev ${TAP}

#Porque TELSERVER tiene dos interfaces
if [ "${NOMBRE_CLIENTE}" == "TELSERVER" ]
then
	sudo openvpn --rmtun --dev ${TELSERVER2[0]}
fi

exit 0
